// NMI's Java Code Viewer 6.0a
// www.trinnion.com/javacodeviewer

// Registered to Evaluation Copy                                      
// Generated PGFZKD AyTB 14 2007 15:43:34 

//source File Name:   IndicatorBase.java

package com.chiyou.common.indicator;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

import com.chiyou.common.models.HisData;


// Referenced classes of package gnnt.MEBS.HQApplet.Indicator:
//            IndicatorPos

public abstract class IndicatorBase {

	
    String m_strIndicatorName;
    protected KLineData m_kData[];
    protected IndicatorPos m_pos;
    protected float m_max;
    protected float m_min;
    protected int m_iTextH;
    protected float m_data[][];
    protected String m_strParamName[];
	protected int m_iPrecision;
	private List<HisData> m_kDatas;
    public List<HisData> getM_kDatas() {
		return m_kDatas;
	}

	public void setM_kDatas(List<HisData> m_kDatas) {
		this.m_kDatas = m_kDatas;
	}

	public List getIndicators() {
		return indicators;
	}

	public void setIndicators(List indicators) {
		this.indicators = indicators;
	}
	
	public void addIndicators(Object indicObj){
		if (indicators == null || indicators.equals(null)  ) {
			indicators =  new ArrayList();
		
		}
		
		if(indicObj != null && !indicObj.equals(null)){
			indicators.add(indicObj);
		}
	}

	List indicators;
    public static final String INDICATOR_NAME[][] = {
        {
            "ASI", "\u7D2F\u8BA1\u632F\u8361\u6307\u6807"
        }, {
            "BIAS", "\u4E56\u79BB\u7387"
        }, {
            "BRAR", "BRAR\u80FD\u91CF\u6307\u6807"
        }, {
            "BOLL", "\u5E03\u6797\u7EBF"
        }, {
            "CCI", "\u987A\u52BF\u6307\u6807"
        }, {
            "CR", "CR\u80FD\u91CF\u6307\u6807"
        }, {
            "DMA", "\u5E73\u5747\u7EBF\u5DEE"
        }, {
            "DMI", "\u8D8B\u5411\u6307\u6807"
        }, {
            "EMV", "\u7B80\u6613\u6CE2\u52A8\u6307\u6807"
        }, {
            "EXPMA", "\u6307\u6570\u5E73\u5747\u6570"
        }, {
            "KDJ", "\u968F\u673A\u6307\u6807"
        }, {
            "MACD", "\u5E73\u6ED1\u5F02\u540C\u79FB\u52A8\u5E73\u5747\u7EBF"
        }, {
            "MIKE", "\u9EA6\u514B\u6307\u6807"
        }, {
            "OBV", "\u80FD\u91CF\u6F6E"
        }, {
            "PSY", "\u5FC3\u7406\u7EBF"
        }, {
            "ROC", "\u53D8\u52A8\u901F\u7387"
        }, {
            "RSI", "\u76F8\u5BF9\u5F3A\u5F31\u6307\u6807"
        }, {
            "SAR", "\u629B\u7269\u7EBF\u6307\u6807"
        }, {
            "TRIX", "\u4E09\u91CD\u6307\u6570\u5E73\u5747"
        }, {
            "VR", "\u6210\u4EA4\u91CF\u53D8\u5F02\u7387"
        }, {
            "W%R", "\u5A01\u5EC9\u6307\u6807"
        }, {
            "WVAD", "\u5A01\u5EC9\u53D8\u5F02\u79BB\u6563\u91CF"
        }, {
            "ORDER", "\u8BA2\u8D27\u91CF"
        }
    };

    public IndicatorBase(){
    	
    }
    
    public IndicatorBase(IndicatorPos pos, int iPrecision) {
        m_iTextH = 12;
        m_pos = pos;
        m_iPrecision = iPrecision;
    }

 

    public KLineData[] getM_kData() {
		return m_kData;
	}

	public void setM_kData(KLineData[] m_kData) {
		this.m_kData = m_kData;
	}

	public abstract void Calculate();


 
    

    final void GetValueMaxMin(float data[], int iFirst) {
        if(data == null)
            return;
        int begin = m_pos.m_Begin > iFirst ? m_pos.m_Begin : iFirst;
        int end = m_pos.m_End;
        for(int i = begin; i <= end; i++) {
            if(i >= data.length)
                break;
            if(data[i] > m_max)
                m_max = data[i];
            if(data[i] < m_min)
                m_min = data[i];
        }

    }

   

    protected void AverageClose(int iParam, float data[]) {
        if(m_kData == null || m_kData.length == 0)
            return;
        int n = iParam;
        if(n > m_kData.length || n < 1)
            return;
        float preClose = 0.0F;
        double sum = 0.0D;
        for(int i = 0; i < n - 1; i++)
            sum += m_kData[i].getClosePrice();

        for(int i = n - 1; i < m_kData.length; i++) {
            sum -= preClose;
            sum += m_kData[i].getClosePrice();
            data[i] = (float)(sum / (double)n);
            preClose = m_kData[(i - n) + 1].getClosePrice();
        }

    }

    protected void AverageHigh(int iParam, float data[]) {
        if(m_kData == null || m_kData.length == 0)
            return;
        int n = iParam;
        if(n > m_kData.length || n < 1)
            return;
        float preHigh = 0.0F;
        double sum = 0.0D;
        for(int i = 0; i < n - 1; i++)
            sum += m_kData[i].getHighPrice();

        for(int i = n - 1; i < m_kData.length; i++) {
            sum -= preHigh;
            sum += m_kData[i].getHighPrice();
            data[i] = (float)(sum / (double)n);
            preHigh = m_kData[(i - n) + 1].getHighPrice();
        }

    }

    protected void AverageLow(int iParam, float data[]) {
        if(m_kData == null || m_kData.length == 0)
            return;
        int n = iParam;
        if(n > m_kData.length || n < 1)
            return;
        float preLow = 0.0F;
        double sum = 0.0D;
        for(int i = 0; i < n - 1; i++)
            sum += m_kData[i].getLowPrice();

        for(int i = n - 1; i < m_kData.length; i++) {
            sum -= preLow;
            sum += m_kData[i].getLowPrice();
            data[i] = (float)(sum / (double)n);
            preLow = m_kData[(i - n) + 1].getLowPrice();
        }

    }

    public abstract int isBuyOrSell();
   

    
    
    static void Average(int begin, int iCount, int n, float source[], float destination[]) {
        if(source == null || destination == null)
            return;
        if(n > iCount - begin || n < 1)
            return;
        float prevalue = 0.0F;
        double sum = 0.0D;
        for(int i = iCount - 1; i > iCount - n; i--)
            sum += source[i];

        for(int i = iCount - 1; i >= (begin + n) - 1; i--) {
            sum -= prevalue;
            sum += source[(i - n) + 1];
            prevalue = source[i];
            destination[i] = (float)(sum / (double)n);
        }

    }

}
